﻿package mortal.game.view.copy.groupCopy.view
{
    import Message.Public.*;
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import extend.language.*;
    import fl.data.*;
    import flash.events.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.button.*;
    import mortal.game.view.common.pageSelect.*;
    import mortal.mvc.core.*;

    public class GroupCopyMateInfoPanel extends GroupCopyBaseListPanel
    {
        private var _groupMateList:GTileList;
        private var _btnCopySetting:GButton;
        private var _btnCopyEnter:GButton;
        private var _brocastBtn:TimeButton;
        private var _pageSelecter:PageSelecter;
        private var _autoEnter:GCheckBox;

        public function GroupCopyMateInfoPanel()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._groupMateList = UIFactory.tileList(30, 62, 465, 255, this);
            this._groupMateList.columnWidth = 460;
            this._groupMateList.rowHeight = 45;
            this._groupMateList.horizontalGap = 6;
            this._groupMateList.verticalGap = 1;
            this._groupMateList.setStyle("cellRenderer", GroupCopyMateRender);
            this._groupMateList.isClickedUpdate = false;
            this._btnCopySetting = UIFactory.gButton(Language.getString(35227), 170, 296, 84, 27, this, "BrownBtn");
            this._btnCopySetting.configEventListener(MouseEvent.CLICK, this.clickHandler);
            this._btnCopyEnter = UIFactory.gButton(Language.getString(35228), 280, 296, 84, 27, this, "BrownBtn");
            this._btnCopyEnter.name = "GroupCopy_EnterCopyBtn";
            this._btnCopyEnter.configEventListener(MouseEvent.CLICK, this.clickHandler);
            this._brocastBtn = UIFactory.timeButton(Language.getString(35229), 34, 296, 65, 27, this, "Duiwuzhaomu", "PackButton", false);
            this._brocastBtn.cdTime = 10000;
            this._brocastBtn.configEventListener(MouseEvent.CLICK, this.clickHandler);
            this._autoEnter = UIFactory.checkBox(Language.getString(35230), 375, 297, 130, 28, this);
            this._autoEnter.configEventListener(Event.CHANGE, this.autoEnter);
            LoaderHelp.addResCallBack(ResFileConst.groupCopy, this.showSkin);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._btnCopyEnter.name = "";
            this._btnCopySetting.dispose(param1);
            this._btnCopySetting = null;
            this._btnCopyEnter.dispose(param1);
            this._btnCopyEnter = null;
            this._groupMateList.dispose(param1);
            this._groupMateList = null;
            this._autoEnter.dispose(param1);
            this._autoEnter = null;
            if (this._brocastBtn)
            {
                this._brocastBtn.dispose(param1);
                this._brocastBtn = null;
            }
            super.disposeImpl(param1);
            return;
        }// end function

        private function showSkin() : void
        {
            if (isDisposed)
            {
                return;
            }
            this.pushUIToDisposeVec(UIFactory.gBitmap(ImagesConst.groupCopyTxt_11, 46, 42, this));
            this.pushUIToDisposeVec(UIFactory.gBitmap(ImagesConst.groupCopyTxt_13, 190, 42, this));
            this.pushUIToDisposeVec(UIFactory.gBitmap(ImagesConst.groupCopyTxt_12, 321, 42, this));
            this.pushUIToDisposeVec(UIFactory.gBitmap(ImagesConst.groupCopyTxt_5, 435, 42, this));
            return;
        }// end function

        private function autoEnter(event:Event) : void
        {
            var isTeamInCopy:Boolean;
            var mapArr:Array;
            var i:SGroupPlayer;
            var e:* = event;
            Cache.instance.group.groupCopyAutoEnter = this._autoEnter.selected;
            if (this._autoEnter.selected)
            {
                mapArr = CopyConfig.instance.getCopyInfoByCode(Cache.instance.group.sgroup.copyCode).maps.split("#");
                var _loc_3:int = 0;
                var _loc_4:* = Cache.instance.group.players;
                while (_loc_4 in _loc_3)
                {
                    
                    i = _loc_4[_loc_3];
                    if (mapArr.indexOf(i.player.mapId.toString()) >= 0)
                    {
                        isTeamInCopy;
                        break;
                    }
                }
                if (!isTeamInCopy && Cache.instance.group.isInCopyGroup && Cache.instance.group.isCaptain && !Cache.instance.copy.isInCopy)
                {
                    var autoEnter:* = function () : void
            {
                if (Cache.instance.copy.copyInfo && Cache.instance.copy.copyInfo.type == ECopyType._ECopyTypeTeam)
                {
                }
                else
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.CopyGroupEnter, _tcopy.code));
                }
                return;
            }// end function
            ;
                    if (Cache.instance.group.players.length == 5 && Cache.instance.group.groupCopyAutoEnter)
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.CopyGroupEnter, _tcopy.code));
                    }
                }
            }
            return;
        }// end function

        private function clickHandler(event:MouseEvent) : void
        {
            if (event.currentTarget == this._btnCopySetting)
            {
                GroupCopySettingWin.instance.show();
                GroupCopySettingWin.instance.data = _tcopy;
            }
            else if (event.currentTarget == this._btnCopyEnter)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.CopyGroupEnter, _tcopy.code));
            }
            else if (event.currentTarget == this._brocastBtn)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.CopyGroupRecruit));
            }
            return;
        }// end function

        public function updateGroupMateList(param1:Array = null) : void
        {
            var _loc_5:int = 0;
            var _loc_6:Object = null;
            var _loc_7:SGroupPlayer = null;
            var _loc_2:* = new DataProvider();
            var _loc_3:* = Cache.instance.group.players;
            var _loc_4:* = _loc_3.length;
            while (_loc_5 < 5)
            {
                
                _loc_6 = new Object();
                _loc_6.index = _loc_5;
                if (_loc_3[_loc_5])
                {
                    _loc_7 = _loc_3[_loc_5];
                    _loc_6.data = _loc_7;
                }
                _loc_2.addItem(_loc_6);
                _loc_5++;
            }
            this._groupMateList.dataProvider = _loc_2;
            if (Cache.instance.group.isCaptain)
            {
                this._btnCopySetting.enabled = true;
                this._autoEnter.visible = true;
                this._autoEnter.selected = Cache.instance.group.groupCopyAutoEnter;
            }
            else
            {
                this._autoEnter.visible = false;
                this._btnCopySetting.enabled = false;
            }
            if (Cache.instance.group.isCaptain && !CopyUtil.isInGroupCopy && Cache.instance.group.sgroup.players.length < 5)
            {
                this._brocastBtn.clickEnble = true;
            }
            else
            {
                this._brocastBtn.clickEnble = false;
            }
            return;
        }// end function

    }
}
